<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>{:config('WEB_SITE_TITLE')}后台管理系统</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="{$statics}bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="{$css_path}font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="{$css_path}ionicons/css/ionicons.min.css">
  <link rel="stylesheet" href="{$css_path}AdminLTE.min.css">
  <link rel="stylesheet" href="{$css_path}skins/_all-skins.min.css">
  <link rel="stylesheet" href="{$statics}plugins/iCheck/flat/blue.css">
  <link rel="stylesheet" href="{$statics}plugins/morris/morris.css">
  <link rel="stylesheet" href="{$statics}plugins/jvectormap/jquery-jvectormap-1.2.2.css">
  <link rel="stylesheet" href="{$statics}plugins/datepicker/datepicker3.css">
  <link rel="stylesheet" href="{$statics}plugins/daterangepicker/daterangepicker.css">
  <link rel="stylesheet" href="{$statics}plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
  <link rel="stylesheet" type="text/css" href="{$statics}layui/css/layui.css">
  <link rel="stylesheet" type="text/css" href="{$statics}plugins/upload/uploadifive.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <script type="text/javascript">
  var searchMap = {};var totalPages = 0;
  {if condition="isset($model) && $model neq ''"}
  searchMap.model = "{$model}"; //数据模型名称
    {if condition="isset($modelPk) && $modelPk neq ''"}
    searchMap.modelPk = "{$modelPk}"; //数据模型名称
    {/if}
    {if condition="isset($whereData) && is_array($whereData)"}
    searchMap.whereData = {:json_encode($whereData)}; //数据模型名称
    {/if}
  {/if}
  var APP_URL = "{$app_url}";
  var default_pageid = "pages";
  //默认信息保存路径
  var defaultSaveUrl = "{:url('data_save')}";
  //默认获取总页数地址
  var defaultPagesUrl = "{:url('get_pages')}";
  //默认获取数据展示列表
  var defaultDataUrl = "{:url('data_show')}";
  //默认获取数据保存地址
  var defaultUpdateUrl = "{:url('data_edit')}";
  //修改某个字段
  var defaultSetFieldUrl = "{:url('set_field')}";
  //默认获取数据删除地址
  var defaultDeleteUrl = "{:url('data_delete',array('model'=>$model))}";

  var upload_url = "{:url('upload')}";

  var defaultEditUrl = "{:isset($editurl) ? $editurl : url('edit')}";

  var defaultExportUrl = "{:url('data_export')}";
  </script>
  {block name="css"}
  <!-- css代码 -->
  {/block}
</head>
<body class="hold-transition skin-green-light sidebar-mini" style="background: #FFF">
<div class="wrapper">
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper" style="background: #FFF;margin-left:0;border-left:none">
    <div class="layui-tab layui-tab-card" lay-filter="demo" lay-allowclose="true" style="margin:0">
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          {block name="content"}
          <!-- 主体内容 -->
          {/block}
        </div>
      </div>
    </div>
  </div>
  <!-- /.content-wrapper -->
</div>
<!-- ./wrapper -->
<script src="{$statics}plugins/jQuery/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="{$statics}layui/layui.js"></script>
{block name="script"}
<!-- JS代码 -->
{/block}
<script type="text/javascript" src="{$statics}admin.js?v=5"></script>
<script>
layui.use('table', function(){
  var table = layui.table;
  //监听单元格编辑
  table.on('edit(lists)', function(obj){
    var value = obj.value //得到修改后的值
    ,data = obj.data //得到所在行所有键值
    ,field = obj.field; //得到字段
    // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
    var updatejson = {id:data.id, field:field, value:value};
    $.post(defaultSetFieldUrl,updatejson,function(datajson){
      if(datajson.status != 1){
        layer.msg(datajson.msg);
        return false;
      }
    },'json');
  });

  var $ = layui.$;
  var active = {
    delAll:function(){
      var checkStatus = table.checkStatus('lists');
      var data = checkStatus.data;
      var nums = data.length;
      if(nums == 0){
        layer.msg("请至少选择1项进行操作！");
        return false;
      }
      var items = '';
      $(data).each(function(index,item){
        items += item.id + ',';
      });
      $(this).attr("items",items);
      cocoAjaxAction(this,table);
    }
  };
  $('#toolbar .btnAction').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  table.on('tool(lists)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data; //获得当前行数据
    var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
    var tr = obj.tr; //获得当前行 tr 的DOM对象
   if (window.location.pathname == '/admin/adminuser/index.html' || window.location.pathname == '/admin/adminuser/index_dealer.html') {
    data.id = data.userid;
   }
    if(layEvent === 'detail'){ //查看
      //do somehing
    }
    else if(layEvent === 'del'){ //删除
      layer.confirm('您确定要删除吗？', function(index){
        $.post(defaultDeleteUrl,{items:data.id},function(datajson){
          obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
          layer.close(index);
        },'json');
      });
    }
    else if (layEvent === 'openimg') {
        layer.open({
            type: 2,
            area: ['800px', '700px'],
            fixed: false, //不固定
            maxmin: true,
            content: APP_URL+"/admin/article/image?cover="+data.cover,
            title:'封面图',
            shade: [0.8, '#000000']
        });
    }
    else if(layEvent === 'edit'){ //编辑
      var layindex = layer.open({
        type: 2,
        area: ['800px', '530px'],
        fixed: false, //不固定
        maxmin: true,
        content: defaultEditUrl+"?items="+data.id,
        title:'修改信息',
        btn: ['确定', '取消'],
        shade: [0.8, '#000000'],
        yes:function(index,layero){
          //parent.$('#parentIframe').text('我被改变了');
          var iframeWin = window[layero.find('iframe')[0]['name']];
          formobj = iframeWin.$("form");
          ajaxUrl = formobj.attr("action");
          if(ajaxUrl == undefined || ajaxUrl == ''){
            ajaxUrl = defaultSaveUrl;
          }
          datajson = formobj.serialize();
          searchMap.postData = datajson;
          console.log(datajson);
          // parent.obj.update(datajson);
          $.post(ajaxUrl,searchMap,function(datajson){
            var serializeObj={};
            if(datajson.status == 1){
              $(formobj.serializeArray()).each(function(){
                serializeObj[this.name]=this.value;
              });
              obj.update(serializeObj);
              layer.msg("操作成功",function(){
                layer.closeAll();
              });
              setTimeout(function() {
                location.reload();
              }, 300);
            }
            else{
              layer.msg(datajson.msg);
              return false;
            }
          },'json');
        }
      });
      // location.href = APP_URL + window.location.pathname + '?pid=' + data.id
      // layer.full(layindex);
    }
    else{
      eval(layEvent)(data);
    }
  });
});
</script>
</body>
</html>